import Cookies from 'js-cookie'

const TokenKey = 'oauth-Token'
const StoreUser = 'storeUser'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUser(key) {
  let userStr = localStorage.getItem(StoreUser);
  if (userStr) {
    let userObj = JSON.parse(userStr);
    return userObj[key];
  }
}

export function setUser(data) {
  data = JSON.stringify(data);
  return localStorage.setItem(StoreUser, data);
}

export function removeUser() {
  return localStorage.removeItem(StoreUser);
}
